package com.allprs.hmcs.service.impl;

import com.allprs.common.core.domain.AjaxResult;
import com.allprs.common.utils.StringUtils;
import com.allprs.common.utils.uuid.IdUtils;
import com.allprs.hmcs.entity.EmergencyPlan;
import com.allprs.hmcs.entity.HyParking;
import com.allprs.hmcs.entity.NaturalWater;
import com.allprs.hmcs.mapper.EmergencyPlanMapper;
import com.allprs.hmcs.pojo.reqBo.EmergencyPlanQueryBo;
import com.allprs.hmcs.service.IEmergencyPlanService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wjf
 * @描述:
 * @date 2024年11月06日
 * @version: 1.0
 */

@Service
public class EmergencyPlanServiceImpl implements IEmergencyPlanService {

    @Resource
    private EmergencyPlanMapper emergencyPlanMapper;


    @Override
    public AjaxResult addPlan(EmergencyPlan vo) {
        vo.setId(IdUtils.fastSimpleUUID());
        int i = emergencyPlanMapper.insert(vo);
        return i > 0 ? AjaxResult.success("新增成功！"):AjaxResult.error("新增失败！");
    }

    @Override
    public List<EmergencyPlan> getList(EmergencyPlanQueryBo queryBo) {
        QueryWrapper<EmergencyPlan> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(queryBo.getName()), "name", queryBo.getName())
                .like(StringUtils.isNotBlank(queryBo.getType()), "type", queryBo.getType())
                .like(StringUtils.isNotBlank(queryBo.getUnits()), "units", queryBo.getUnits())
                .like(StringUtils.isNotBlank(queryBo.getCategory()), "category", queryBo.getCategory());

        List<EmergencyPlan> emergencyPlans = emergencyPlanMapper.selectList(queryWrapper);
        return emergencyPlans;
    }

    @Override
    public AjaxResult getInfo(String id) {
        EmergencyPlan emergencyPlan = emergencyPlanMapper.selectById(id);
        return AjaxResult.success(emergencyPlan);
    }

    @Override
    public AjaxResult update(EmergencyPlan vo) {
        int i = emergencyPlanMapper.updateById(vo);
        return i > 0 ? AjaxResult.success("修改成功！"):AjaxResult.error("修改失败！");
    }

    @Override
    public AjaxResult delete(String id) {
        int i = emergencyPlanMapper.deleteById(id);
        return i > 0 ? AjaxResult.success("删除成功！"):AjaxResult.error("删除失败！");
    }

}
